package com.chaoyi.util.schedule.job;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.chaoyi.SpringContext;
import com.chaoyi.service.OrderService;

public class StatJob implements Runnable{
	private final Logger logger = LoggerFactory.getLogger(StatJob.class);
	
	@Override
	public void run() {
		OrderService orderService = SpringContext.getContext().getBean(OrderService.class);
		LocalDate startTime = LocalDate.now().plusDays(-1);
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		if(logger.isInfoEnabled())
			logger.info("开始统计订单数据，startTime="+startTime+" endTime="+startTime);
		try{
			orderService.orderStat(formatter.format(startTime), formatter.format(startTime));
		}catch(Exception e){
			logger.error("统计订单失败：",e);
		}
		if(logger.isInfoEnabled())
			logger.info("完成统计订单数据");
		if(logger.isInfoEnabled())
			logger.info("开始统计隔天用户数据，startTime="+startTime+" endTime="+startTime);
	}

}
